package com.example.TeacherComponent;

import com.example.AdminComponent.BoxUlit;
import com.example.Utils.Bese;
import com.example.Utils.HttpUtil;
import com.example.Utils.ResultUtil;

import javax.swing.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.util.HashMap;
import java.util.Map;

public class addJFrameTeacherCourse extends JFrame {

    public addJFrameTeacherCourse(){
            String result = HttpUtil.sendPost("http://localhost:8080/teachers");
            String[] strings= ResultUtil.ResultVectorTeachers(result);
            super.setTitle("修改");
            setLocationRelativeTo(null);
            setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);
            setVisible(true);
            setSize(400, 400);
            JPanel jPanel = new JPanel();
            Box big = Box.createVerticalBox();
            //确定按钮
            JButton b1 = new JButton("确定");
            //取消按钮
            JButton b2 = new JButton("取消");
            //退出按钮
            //学号
            Box idBox = Box.createHorizontalBox();
            JLabel idLabel = new JLabel("课程号");
            JTextField idText = new JTextField();
            idBox.add(idLabel);
            idBox.add(Box.createHorizontalStrut(10));
            idBox.add(idText);
            //姓名
            BoxUlit nameBox = new BoxUlit("课程名");
            //学时
            BoxUlit creditHour=new BoxUlit("学时");
            //教师
            JLabel teacherLabel=new JLabel("教师");
            JComboBox<String> teacher=new JComboBox<>(strings);
            Box teacherBox=Box.createHorizontalBox();
            teacherBox.add(teacherLabel);
            teacherBox.add(Box.createHorizontalStrut(5));
            teacherBox.add(teacher);
            BoxUlit periodBox=new BoxUlit("时期");
            BoxUlit timeBox = new BoxUlit("上课时间");
            BoxUlit roomBox = new BoxUlit("上课地点");
            BoxUlit introBox=new BoxUlit("简介");
            JLabel statusLabel=new JLabel("状态");
/*            String[]strings1={"可选（激活）","等待课程安排"};
            JComboBox<String> status=new JComboBox<>(strings1);
            Box statusBox=Box.createHorizontalBox();
            statusBox.add(statusLabel);
            statusBox.add(Box.createHorizontalStrut(5));
            statusBox.add(status);*/
            big.add(Box.createVerticalStrut(30));
            big.add(idBox);
            big.add(Box.createVerticalStrut(5));
            big.add(nameBox);
            big.add(Box.createVerticalStrut(5));
            big.add(creditHour);
            big.add(Box.createVerticalStrut(5));
            big.add(teacherBox);
            big.add(Box.createVerticalStrut(5));
            big.add(periodBox);
            big.add(Box.createVerticalStrut(5));
            big.add(timeBox);
            big.add(Box.createVerticalStrut(5));
            big.add(roomBox);
            big.add(Box.createVerticalStrut(5));
            big.add(introBox);
            big.add(Box.createVerticalStrut(5));
          //  big.add(statusBox);
            big.add(Box.createVerticalStrut(25));
            Box buttons = Box.createHorizontalBox();
            buttons.add(b1);
            buttons.add(Box.createHorizontalStrut(40));
            buttons.add(b2);
            big.add(buttons);
            jPanel.add(big);
            add(jPanel);
            //取消事件
            b2.addActionListener(new ActionListener() {
                @Override
                public void actionPerformed(ActionEvent e) {
                    dispose();
                }
            });

            //确定事件
            b1.addActionListener(new ActionListener() {
                @Override
                public void actionPerformed(ActionEvent e) {
                    Map<String, String> map = new HashMap<>();
                    map.put("id", idText.getText());
                    map.put("name", nameBox.idText.getText());
                    map.put("teacher", teacher.getSelectedItem().toString());
                    map.put("creditHour",creditHour.idText.getText());
                    map.put("period",periodBox.idText.getText());
                    map.put("classTime", timeBox.idText.getText());
                    map.put("classRoom", roomBox.idText.getText());
                    map.put("intro",introBox.idText.getText());
                    map.put("state","0");
                    HttpUtil.sendPost("http://localhost:8080/course/add", map);
                    JOptionPane.showMessageDialog(null, "申请成功，等待教务处回应");
                    dispose();
                }
            });


        }
    }